/**
 * Created by dukes on 2016/1/14.
 */
class BattleRecordItem extends eui.ItemRenderer{
    constructor(){
        super();
        this.skinName = "pet.BattleRecordItemSkin";
    }
    private visitData;
    private onVisit(evt:egret.TouchEvent){
        DateScene.getInstance().forceDisplay(this.visitData);
    }
    /**
     * popularity: 0
     * rank: 10
     * userId: 1008
     * userName: "AFD4836712C5E77550897E25711E1D96"
     * **/
    public dataChanged(){
        super.dataChanged();
        this.lab_record.textFlow = this.getTextFlows(this.data);
    }

    public getTextFlows(data):any[]{
        var arr = [];
        if( data.pillagerId == Model.me.id){
            this.visitData = { userName:data.userName,userId:data.userId,userFigureurl:data.userFigure};
        }else{
            this.visitData = { userName:data.pillagerName,userId:data.pillagerId,userFigureurl:data.pillagerFigure};
        }
        var attackName:string = data.userId == Model.me.id ? "我" : data.userName;
        var temp = {
            text:LimitStringLen(attackName,7),
            style:{
                "textColor": 0x915a07,
                "size":16,
            }
        };
        arr.push(temp);
        temp={
            text:" 挑战 ",
            style:{
                "textColor": 0xf20909,
                "size":16,
            }
        };
        arr.push(temp);
        var beAttackName:string = data.pillagerId == Model.me.id ?  "我" : data.pillagerName;
        var temp = {
            text:LimitStringLen(beAttackName,7),
            style:{
                "textColor": 0x915a07,
                "size":16,
            }
        };
        arr.push(temp);
        var date =  Model.referDate;
        date.setTime(data.recordTime);
        var timestr:string = " "+date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+"\n";
        var temp = {
            text:timestr,
            style:{
                "textColor": 0xcfa840,
                "size":16,
            }
        };
        arr.push(temp);

        if( data.success ){
            if( data.userId == Model.me.id){
                var pid = data.petId;
            }else{
                pid = data.pillagerPetId;
            }
            var pet = Model.getPetInfoById(pid);
            var hairstr:string = pet.type == Model.GOOD_TYPE_CAT ? "猫毛" : "狗毛";
            if(data.pillagerId == Model.me.id){
                temp = {
                    text:"-"+GetNumString(data.hair,false,true),
                    style:{
                        "textColor": 0xf20909,
                        "size":16,
                    }
                };
                arr.push(temp);
            }else{
                temp = {
                    text:"+"+GetNumString(data.hair,false,true),
                    style:{
                        "textColor": 0x26ac13,
                        "size":16,
                    }
                };
                arr.push(temp);
            }
            temp = {
                text:hairstr,
                style:{
                    "textColor": 0xcfa840,
                    "size":16,
                }
            };
            arr.push(temp);
        }else{
            if(data.pillagerId == Model.me.id){
                temp = {
                    text:"防守成功",
                    style:{
                        "textColor": 0x26ac13,
                        "size":16,
                    }
                };
                arr.push(temp);
            }else{
                temp = {
                    text:"抢毛失败",
                    style:{
                        "textColor": 0xf20909,
                        "size":16,
                    }
                };
                arr.push(temp);
            }
        }
        return arr;
    }

    private lab_record:eui.Label;
    private btn_visit:eui.Image;
    public partAdded(name:string, instance:any){
        super.partAdded(name, instance);
        if( name == "lab_record"){
            this.lab_record = instance;
        }else if( name == "btn_visit"){
            this.btn_visit = instance;
            this.btn_visit.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onVisit, this);
        }
    }
}